<?php
include_once("./_common.php");

$del_m[0] = $_POST['del_m0'];
$del_m[1] = $_POST['del_m1'];
$del_m[2] = $_POST['del_m2'];

$del_i[0] = $_POST['del_i0'];
$del_i[1] = $_POST['del_i1'];
$del_i[2] = $_POST['del_i2'];

$_a = explode('/', $a_name1);
$store_name = (int)$_a[0];
if($store_name<10){
	$store_name = "0".$store_name;
}
echo $store_name;
$a_name = $_a[1];
$upload_sql_m = "";
$todays = date("Y", $g4['server_time']);

if ( $vi_month1 )
	$total = $vi_month1.",".$vi_month2.",".$vi_month3.",".$vi_month4.",".$vi_month5.",".$vi_month6.",".$vi_month7.",".$vi_month8.",".$vi_month9.",".$vi_month10.",".$vi_month11.",".$vi_month12;

if ($todays == '2014'){
	$total_2014 = $total;
	$total_2015 = "";
}else if($todays == '2015'){
	$total_2014 = "";
	$total_2015 = $total;
}

for($i = 0; $i < 3; $i++) {
	$upfile[$i] = "{$g4[path]}/adm/adm_new/file/manage/".$_FILES['m_file' . $i]['name'];
	if(is_uploaded_file($_FILES['m_file' . $i]['tmp_name'])){
		if(move_uploaded_file($_FILES['m_file' . $i]['tmp_name'],$upfile[$i])) {
			$upload_sql_m .= "m_file{$i} = '{$upfile[$i]}', ";
		}
	}
}

$upload_sql_i = "";
for($i = 0; $i < 3; $i++) {
	$upfile[$i] = "{$g4[path]}/adm/adm_new/file/manage/".$_FILES['i_file' . $i]['name'];
	if(is_uploaded_file($_FILES['i_file' . $i]['tmp_name'])){
		if(move_uploaded_file($_FILES['i_file' . $i]['tmp_name'],$upfile[$i])) {
			$upload_sql_i .= "i_file{$i} = '{$upfile[$i]}', ";
		}
	}
}

$delete_sql_m = "";
for($i = 0; $i < 3; $i++) {
	if($del_m[$i] == "1") {
		$delete_sql_m .= "m_file{$i} = '', ";
	}
}

$delete_sql_i = "";
for($i = 0; $i < 3; $i++) {
	if($del_i[$i] == "1") {
		$delete_sql_i .= "i_file{$i} = '', ";
	}
}

$string = "a_area = '$a_area',
			a_zip1 = '$a_zip1',
			a_zip2 = '$a_zip2',
			a_addr1 = '$a_addr1',
			a_addr2 = '$a_addr2',
			a_firstday = '$a_firstday',
			a_years = '$a_years',
			a_day1 = '$a_day1',
			a_day2 = '$a_day2',
			a_day3 = '$a_day3',
			a_day4 = '$a_day4',
			a_email = '$a_email',
			a_openday = '$a_openday',
			a_name1 = '$a_name',
			a_name2 = '$a_name2',
			a_num1 = '$a_num1',
			a_num2 = '$a_num2',
			a_num3 = '$a_num3',
			a_tel = '$a_tel',
			a_hp = '$a_hp',
			a_endday = '$a_endday',
			a_notiday = '$a_notiday',
			a_noti = '$a_noti',
			a_transfer = '$a_transfer',
			a_g_cost = '$a_g_cost',
			a_edu_cost = '$a_edu_cost',
			a_edu_detail = '$a_edu_detail',
			a_edu_num = '$a_edu_num',
			a_edu_time = '$a_edu_time',
			a_b_cost = '$a_b_cost',
			a_h_cost = '$a_h_cost',
			a_h_detail = '$a_h_detail',
			a_i_cost = '$a_i_cost',
			a_i_detail = '$a_i_detail',
			a_i_name = '$a_i_name',
			a_i_tel = '$a_i_tel',
			a_i_r = '$a_i_r',
			a_p_cost = '$a_p_cost',
			a_p_detail = '$a_p_detail',
			a_p_name = '$a_p_name',
			a_p_tel = '$a_p_tel',
			a_p_r = '$a_p_r',
			a_j_cost = '$a_j_cost',
			a_j_detail = '$a_j_detail',
			a_j_name = '$a_j_name',
			a_j_tel = '$a_j_tel',
			a_j_r = '$a_j_r',
			a_s_cost = '$a_s_cost',
			a_s_detail = '$a_s_detail',
			a_s_name = '$a_s_name',
			a_s_tel = '$a_s_tel',
			a_s_r = '$a_s_r',
			a_m_cost = '$a_m_cost',
			a_m_detail = '$a_m_detail',
			a_m_name = '$a_m_name',
			a_m_tel = '$a_m_tel',
			a_m_r = '$a_m_r',
			a_c_cost = '$a_c_cost',
			a_c_detail = '$a_c_detail',
			a_c_name = '$a_c_name',
			a_c_tel = '$a_c_tel',
			a_c_r = '$a_c_r',
			a_f_cost = '$a_f_cost',
			a_f_detail = '$a_f_detail',
			a_f_name = '$a_f_name',
			a_f_tel = '$a_f_tel',
			a_f_r = '$a_f_r',
			a_etc_cost = '$a_etc_cost',
			a_etc_detail = '$a_etc_detail',
			a_supp_cost = '$a_supp_cost',
			a_supp_detail = '$a_supp_detail',
			$upload_sql_m
			$delete_sql_m
			$upload_sql_i
			$delete_sql_i
			a_content = '$a_content',
			s_map_x = '$s_map_x',
			s_map_y = '$s_map_y',
			s_zoom_level = '$s_zoom_level',
			s_point_x = '$s_point_x',
			s_point_y = '$s_point_y',
			store_num = '$store_name',
			vi_month1 = '$vi_month1',
			vi_month2 = '$vi_month2',
			vi_month3 = '$vi_month3',
			vi_month4 = '$vi_month4',
			vi_month5 = '$vi_month5',
			vi_month6 = '$vi_month6',
			vi_month7 = '$vi_month7',
			vi_month8 = '$vi_month8',
			vi_month9 = '$vi_month9',
			vi_month10 = '$vi_month10',
			vi_month11 = '$vi_month11',
			vi_month12 = '$vi_month12'";
if ($total){
	$avg = "store_name = '$a_name',
			store_num =  '$store_name',
			longitude = '$s_map_x',
			latitude = '$s_map_y',
			y2014 = '$total_2014',
			y2015 = '$total_2015'";
}
if($w == "") {
	$sql = "INSERT
			INTO	manage
			SET		$string";
	$rst = sql_query($sql);
	if ($total){
		$sql2 = "INSERT
				INTO	month_avg
				SET		$avg";
		$rst = sql_query($sql2);
	}
} else if ($w == "u") {
	$sql = "UPDATE	manage
			SET		$string
			WHERE	id = '$id'";
	$rst = sql_query($sql);
	
	if ($total){
		
	}
} else if ($w == "d") {
	$sql = "DELETE
			FROM	manage
			WHERE	id = '$id'";
	$rst = sql_query($sql);
}

if($w == "") {
	alert("등록되었습니다.", "./manage.php?bo_table=manage");
} else if ($w == "u") {
	alert("수정되었습니다.", "./manage_view.php?bo_table=manage&id=$id");
} else if ($w == "d") {
	alert("삭제되었습니다.", "./manage.php?bo_table=manage");
}
?>
